#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>
#include <signal.h>
#include <pwd.h>

void sig_alarm(int signo) {
	struct passwd *rootptr;

	printf("in signal handler\n");
	if ((rootptr=getpwnam("root")) == NULL) {
		printf("getpwnam root error\n");
		return;
	}

	alarm(1);
}

int main(int argc, char const *argv[])
{
	struct passwd *ptr;
	if (signal(SIGALRM, sig_alarm) == SIG_ERR) {
		printf("can't catch SIGALARM\n");
		return -1;
	}
	alarm(1);

	for (; ;) {
		if ((ptr=getpwnam("windy")) == NULL) {
			printf("getpwnam windy error\n");
			return;
		}

		if (strcmp(ptr->pw_name, "windy") != 0)
			printf("return value corrupted!, pw_name= %s\n", \
												 ptr->pw_name);
	}
	
	return 0;
}